package com.lzy.system.organization.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.lzy.system.organization.entity.SysUser;
import com.lzy.system.organization.vo.SysUserVo;
import org.apache.ibatis.annotations.*;
import org.springframework.stereotype.Repository;

import java.util.List;

/**
 * <p>
 *  Mapper 用户信息
 * </p>
 *
 * @author lcc
 * @since 2022-08-13
 */
@Repository
public interface SysUserMapper extends BaseMapper<SysUser> {
    @Select("select * from sys_user where username=#{username}")
    @Results({
            @Result(id = true, property = "id", column = "id"),
            @Result(property = "roles", column = "id", javaType = List.class,
                    many = @Many(select = "com.lzy.system.organization.mapper.SysRoleMapper.selectByUid"))
    })
    public SysUserVo findByUsername(@Param(value = "username") String username);

    @Select("select * from sys_user where id=#{id}")
    @Results({
            @Result(id = true, property = "id", column = "id"),
            @Result(property = "roles", column = "id", javaType = List.class,
                    many = @Many(select = "com.lzy.system.organization.mapper.SysRoleMapper.selectByUid"))
    })
    public SysUserVo findById(@Param(value = "id") Long id);

    @Insert("insert into sys_user(username,password,nickname,status) values (#{username},#{password},#{nickname},1)")
    @Options(useGeneratedKeys = true, keyProperty = "id")
    public int addUser(@Param(value = "sysUser") SysUser sysUser);
}
